/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import doa.TwittererDAO;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import models.Twitterer;

/**
 *
 * @author Misja
 */
public class TwittererBean {

    private Twitterer twitterer;

    public TwittererBean() {
        this.twitterer = new Twitterer();
    }

    public Twitterer getTwitterer() {
        return twitterer;
    }

    public void setTwitterer(Twitterer twitterer) {
        this.twitterer = twitterer;
    }

    public void saveTwitterer() {
        boolean result = TwittererDAO.saveTwitterer(this.twitterer);
        if (result) {
            FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO, "Twitterer is succesfully added", null));
        } else {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Username is already in use", null));          
        }
    }
    
    public String toLogin(){
        return "/Login.xhtml?faces-redirect=true";
    }
}
